import "../global.css";
import { Slot, SplashScreen, Stack } from "expo-router";
import { useFonts } from "expo-font";
import { useEffect } from "react";
import { SafeAreaProvider } from "react-native-safe-area-context";
import TimerProvider from "@/context/TimerContext";
export default function RootLayout() {
  const [fontsLoaded, error] = useFonts({
    "Roboto-Mono": require("../assets/fonts/RobotoMono-Regular.ttf"),
  });
  useEffect(() => {
    if (error) throw error;//果字体加载过程中发生错误，抛出错误
    if (fontsLoaded) SplashScreen.hideAsync();//如果字体加载完成，隐藏启动屏幕
  }, [fontsLoaded, error]);

  if (!fontsLoaded) {
    return null;
  }

  if (!fontsLoaded && !error) {
    return null;
  }
  // return <Slot />
  return (
    
    <SafeAreaProvider>
        <TimerProvider>
            <Stack>
                <Stack.Screen
                    name="(tabs)"
                    options={{ headerShown: false }}
                />
                <Stack.Screen
                    name="meditate/[id]"
                    options={{ headerShown: false }}
                />
                <Stack.Screen
                    name="index"
                    options={{ headerShown: false }}
                />
                <Stack.Screen
                    name="(modal)/adjust-meditation-duration"
                    options={{ headerShown: false, presentation: "modal" }}
                />
            </Stack>
        </TimerProvider>
    </SafeAreaProvider>
);
}